﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.jwxcd.CommunityDriver;
using System.Windows.Controls;
using System.Windows;

namespace PersonHealth
{
    public class MeasureBase : PageBase
    {
        protected IytongDriver driver;

        public MeasureBase()
        {
            driver = new IytongDriver();
            driver.onConnectedEvent += onDriverConnected;
            driver.onDisconnectedEvent += onDriverDisConnected;
            driver.onMeausreEvent += onMeasure;
            driver.onNoticeEvent += onNoticeEvent;

            this.Loaded += new RoutedEventHandler(MeasureBase_Loaded);
            this.Unloaded += new RoutedEventHandler(MeasureBase_Unloaded);
        }
        
        public virtual void MeasureBase_Loaded(object sender, RoutedEventArgs e)
        {
            
        }
        public virtual void MeasureBase_Unloaded(object sender, RoutedEventArgs e)
        {
            driver.disConnect();
        }

        public virtual void onDriverConnected(Object sender, EventArgs e)
        {
            Dispatcher.Invoke(new Action(
                () =>
                {
                    this.Opacity = 1;
                    this.IsEnabled = true;
                    MessageBox.Show("连接成功");
                }));
        }

        private static object lockObj = new object();
        public void onDriverDisConnected(Object sender, EventArgs e)
        {

            //Dispatcher.Invoke(new Action(() => MessageBox.Show("断开成功")));
        }

        public virtual void onMeasure(Object sender, MeasureEventArgs e)
        {
        }

        public virtual void onError(Object sender, MeasureErrorArgs e)
        {
            //Action a = new Action(() => Tools.ShowMessage(false, e.value));
            //Dispatcher.Invoke(a);

        }

        void onNoticeEvent(object sender, MeasureNoticeArgs e)
        {

            //Dispatcher.Invoke(
            //    new Action(() => MessageBox.Show(e.value)), null);


        }

    }
}
